home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / comm / bbs / cit_src_7H21.lha / virt.c < prev    next >
C/C++ Source or Header  |  1997-07-27  |  4KB  |  163 lines

  1. /*                               virt.c
  2. *
  3. * Virtual room handler for Citadel-86.
  4. */
  5. #include "ctdl.h"
  6. /*
  7. *                               history
  8. *
  9. * 91Nov15 HAW Restructured.
  10. * 88Apr01 HAW Final cleanup before release.
  11. */
  12. /*
  13. *                               contents
  14. *
  15. *       VirtInit()              Initialize the virtual room stuff
  16. *       InitVNode()             Init for a new node
  17. *       UpdVirtStuff()          Updates the virtual stuff
  18. *       VirtSummary()           Does real work of updating virtual stuff
  19. *
  20. */
  21. VirtualRoom *VRoomTab;
  22. VirtNet     *VirtNetList;
  23. char VirtualInUse = FALSE;
  24. int  VirtSize, VNetSize;
  25. extern NetBuffer netBuf;
  26. extern CONFIG    cfg;
  27. extern int       thisNet;
  28. extern FILE      *netLog;
  29. extern char      netDebug, TrError;
  30. /*
  31. * VirtInit()
  32. *
  33. * This function initializes the virtual room stuff, if available.  The virtual
  34. * room stuff is created by the virtadmn utility, so this is a non-fatal,
  35. * non-warning failure -- the sysop doesn't even know that this stuff ain't
  36. * here.
  37. */
  38. void VirtInit()
  39.   {
  40.   #ifndef NO_VIRTUAL_ROOMS
  41.   FILE *fd;
  42.   SYS_FILE fn;
  43.   long size;
  44.   extern char *R_W_ANY;
  45.   makeVASysName(fn, "ctdlvrm.sys");
  46.   if ((fd = safeopen(fn, R_W_ANY)) == NULL)
  47.   return;       /* Depend on initializer to handle VirtualInUse */
  48.   totalBytes(&size, fd);
  49.   VRoomTab = (VirtualRoom *) GetDynamic((int) size);
  50.   fread((char *) VRoomTab, (int) size, 1, fd);
  51.   fclose(fd);
  52.   VirtSize = (int) size / sizeof *VRoomTab;
  53.   VirtualInUse = TRUE;
  54.   makeVASysName(fn, "ctdlvnet.sys");
  55.   if ((fd = safeopen(fn, R_W_ANY)) == NULL)
  56.   crashout("ctdlvnet.sys is missing!!");
  57.   totalBytes(&size, fd);
  58.   VirtNetList = (VirtNet *) GetDynamic((int) size);
  59.   VNetSize = size / sizeof *VirtNetList;
  60.   fread(VirtNetList, (int) size, 1, fd);
  61.   fclose(fd);
  62.   #endif
  63.  
  64.   }
  65. /*
  66. * InitVNode()
  67. *
  68. * When a new node is added to the net list, this function initializes the
  69. * virtual part of the new node.  This consists of enlarging the vnet table
  70. * size if necessary, and initializing the room pointers to -1, indicating
  71. * that none of them are in use.  Finally, the virtual tables on disk are
  72. * updated.
  73. */
  74. void InitVNode(int slot)
  75.   {
  76.   #ifndef NO_VIRTUAL_ROOMS
  77.   int rover;
  78.   if (!VirtualInUse) return ;
  79.   if (slot >= VNetSize)
  80.     {
  81.     VirtNetList = realloc(VirtNetList, (slot+1) * sizeof *VirtNetList);
  82.     VNetSize = slot + 1;
  83.  
  84.     }
  85.   for (rover = 0; rover < VIRT_LIMIT; rover++)
  86.   VirtNetList[slot].VirtList[rover].WhichVirt = -1;
  87.   UpdVirtStuff();
  88.   #endif
  89.  
  90.   }
  91. /*
  92. * UpdVirtStuff()
  93. *
  94. * This function updates the virtual data on disk.
  95. */
  96. void UpdVirtStuff()
  97.   {
  98.   #ifndef NO_VIRTUAL_ROOMS
  99.   FILE *fd;
  100.   SYS_FILE fn;
  101.   extern char *R_W_ANY;
  102.   if (!VirtualInUse) return ;
  103.   VirtSummary();
  104.   makeVASysName(fn, "ctdlvrm.sys");
  105.   if ((fd = safeopen(fn, R_W_ANY)) == NULL)
  106.   crashout("ctdlvrm.sys is missing!");
  107.   fwrite(VRoomTab, VirtSize, sizeof *VRoomTab, fd);
  108.   fclose(fd);
  109.   makeVASysName(fn, "ctdlvnet.sys");
  110.   if ((fd = safeopen(fn, R_W_ANY)) == NULL)
  111.   crashout("ctdlvnet.sys is missing!!");
  112.   fwrite(VirtNetList, cfg.netSize, sizeof *VirtNetList,  fd);
  113.   fclose(fd);
  114.   #endif
  115.  
  116.   }
  117. /*
  118. * VirtSummary()
  119. *
  120. * This function handles post-call cleanup.
  121. */
  122. void VirtSummary()
  123.   {
  124.   #ifndef NO_VIRTUAL_ROOMS
  125.   int rover, another;
  126.   for (rover = 0; rover < VirtSize; rover++)
  127.     {
  128.     if (VRoomTab[rover].vrChanged & LD_CHANGE)
  129.       {
  130.       VRoomTab[rover].vrHiLD++;
  131.       for (another = 0; another < VIRT_LIMIT; another++)
  132.       if (VirtNetList[thisNet].VirtList[another].WhichVirt == rover)
  133.         {
  134.         VirtNetList[thisNet].VirtList[another].LDSent =
  135.         VRoomTab[rover].vrHiLD;
  136.         break;
  137.  
  138.         }
  139.       /*if (another == VIRT_LIMIT) splitF(netLog, "Unexpected mistake 1 in LDVirtSummary!\n"); */
  140.  
  141.       }
  142.     if (VRoomTab[rover].vrChanged & LOC_CHANGE)
  143.       {
  144.       VRoomTab[rover].vrHiLocal++;
  145.       for (another = 0; another < VIRT_LIMIT; another++)
  146.       if (VirtNetList[thisNet].VirtList[another].WhichVirt == rover)
  147.  
  148.         {
  149.         VirtNetList[thisNet].VirtList[another].LocSent =
  150.         VRoomTab[rover].vrHiLocal;
  151.         break;
  152.  
  153.         }
  154.       /*if (another == VIRT_LIMIT) splitF(netLog, "Unexpected mistake 2 in LocVirtSummary!\n"); */
  155.  
  156.       }
  157.     VRoomTab[rover].vrChanged = 0;
  158.  
  159.     }
  160.   #endif
  161.  
  162.   }
  163.